package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.businessdepart.config.BusinessDepartConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.activity.businessdepart.BusinessDepartMgr;

import java.util.ArrayList;
import java.util.List;

/**
 * 商途启程道具回收
 */
public class BusinessDepartRecycleStrategy extends AbstractItemRecycleStrategy {

    @Override
    public void markNeedRecycleItem() {
        List<ActivityInfo> activityList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.BusinessDepart.getValue());
        for (ActivityInfo activityInfo : activityList) {
            if (activityInfo != null) {
                //回收时间
                long recycleTime = activityInfo.getEndShowTime() * 1000L + 600 * 1000;
                //回收的道具ID
                BusinessDepartConfig config = BusinessDepartMgr.getConfig(activityInfo.getActivityId());
                if (config != null) {
                    int itemId = config.getEXCHANGE_SCORE_ITEM_ID();
                    List<String> paramList = new ArrayList<>();
                    ActivityItemRecycleMgr.addRecycleItemData(itemId, activityType, 0, recycleTime, paramList);
                }
            }
        }
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.BusinessDepart.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        int itemId = data.getItemId();
        UserBagItem userBagItem = getUserBagItem(userId, itemId);
        if (userBagItem != null && userBagItem.getNum() > 0) {
            this.removeItem(userBagItem);
        }
    }

    @Override
    public boolean isActivityRunning() {
        return false;
    }
}
